package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import javax.security.auth.login.LoginException;

public class ValueAnimationActivity extends AppCompatActivity {
    private static final String TAG = "ValueAnimationActivity";
    Button mBtnStart;
    TextView mTvMsg;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_value_animation);
        initView();
        initEvent();
    }

    private void initEvent() {
        mBtnStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ValueAnimator valueAnimator=ValueAnimator.ofFloat(0f,5f,2,3f);
                valueAnimator.setDuration(2000);
                valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(mTvMsg,"rotation",0,360f);
                        objectAnimator.setDuration(2000);
                        objectAnimator.start();
//                        mTvMsg.setBackgroundColor((int)(0xFFFF0000*(float)animation.getAnimatedValue()));
//                        mTvMsg.setTextSize(20*((float)animation.getAnimatedValue()+1));
//                        mTvMsg.setLeft((int)(20*((float)animation.getAnimatedValue())));
//                        Log.e(TAG,"onAnimationUpdate:"+animation.getAnimatedValue());
//                        Toast.makeText(ValueAnimationActivity.this, "动画启动了！"+animation.getAnimatedValue(), Toast.LENGTH_SHORT).show();
                    }
                });
                valueAnimator.start();
            }
        });
    }

    private void initView() {
        mBtnStart=findViewById(R.id.btn_start);
        mTvMsg=findViewById(R.id.tv_msg);

    }
}